import sys
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
                            QMetaObject, QObject, QPoint, QRect,
                            QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
                           QFont, QFontDatabase, QGradient, QIcon,
                           QImage, QKeySequence, QLinearGradient, QPainter,
                           QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QComboBox, QDateEdit, QGridLayout,
                               QLabel, QLineEdit, QSizePolicy, QWidget, QSpacerItem)
from qfluentwidgets import SearchLineEdit, ZhDatePicker, SubtitleLabel, ComboBox, ZhDatePicker


class ItemSelectBar(QWidget):
    def __init__(self):
        super().__init__()
        self.itemSelectComboBox = None
        self.searchItemLineEdit = None
        self.endDateEdit = None
        self.startDateEdit = None
        self.startDateLabel = None
        self.endDateLabel = None
        self.gridLayout = None
        self.setupUi()

    def setupUi(self):
        self.gridLayout = QGridLayout(self)
        self.gridLayout.setHorizontalSpacing(30)
        self.gridLayout.setVerticalSpacing(15)
        self.gridLayout.setContentsMargins(20, 0, 20, 0)

        font = QFont()
        font.setPointSize(10)

        self.startDateLabel = QLabel()
        self.startDateLabel.setText("开始日期")
        self.startDateLabel.setFont(font)
        self.startDateLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
        self.gridLayout.addWidget(self.startDateLabel, 0, 1, 1, 1)

        self.endDateLabel = QLabel()
        self.endDateLabel.setText("结束日期")
        self.endDateLabel.setFont(font)
        self.endDateLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
        self.gridLayout.addWidget(self.endDateLabel, 0, 2, 1, 1)

        self.startDateEdit = ZhDatePicker()
        self.startDateEdit.setMinimumSize(QSize(140, 35))
        self.gridLayout.addWidget(self.startDateEdit, 1, 1, 1, 1)

        self.endDateEdit = ZhDatePicker(self)
        self.endDateEdit.setMinimumSize(QSize(0, 35))
        self.gridLayout.addWidget(self.endDateEdit, 1, 2, 1, 1)

        self.itemSelectComboBox = ComboBox(self)
        self.itemSelectComboBox.setPlaceholderText("请选择项目")
        self.itemSelectComboBox.setStyleSheet("QComboBox { padding-left: 30px; padding-right: 30px; }")
        self.itemSelectComboBox.setCurrentIndex(-1)
        sizePolicy = QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.itemSelectComboBox.sizePolicy().hasHeightForWidth())
        self.itemSelectComboBox.setSizePolicy(sizePolicy)
        self.itemSelectComboBox.setMinimumSize(QSize(220, 35))
        self.gridLayout.addWidget(self.itemSelectComboBox, 1, 0, 1, 1)

        self.searchItemLineEdit = SearchLineEdit()
        self.searchItemLineEdit.setPlaceholderText("请输入项目名称")
        sizePolicy.setHeightForWidth(self.searchItemLineEdit.sizePolicy().hasHeightForWidth())
        self.searchItemLineEdit.setSizePolicy(sizePolicy)
        self.searchItemLineEdit.setMinimumSize(QSize(220, 33))
        self.gridLayout.addWidget(self.searchItemLineEdit, 0, 0, 1, 1)

        self.gridLayout.setAlignment(self.itemSelectComboBox, Qt.AlignmentFlag.AlignLeft)
        self.gridLayout.setAlignment(self.searchItemLineEdit, Qt.AlignmentFlag.AlignLeft)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ui = ItemSelectBar()
    ui.show()
    sys.exit(app.exec())
